import java.sql.Connection;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class ClientReports extends GeneralReports {

	public ClientReports(Connection initConnection, DepositDBManager depositDBManager, CustomerDBManager customerDBManager, AccountDBManager accountDBManager, BalanceDBManager balanceDBManager, DepositTypesDBManager depositTypesDBManager) {
		super(initConnection, depositDBManager, customerDBManager, accountDBManager, balanceDBManager, depositTypesDBManager);
	}

	// List of customer's deposits
	public List<Deposit> getListDepositsByCust_id(long cust_id) throws DBManagerException {

		listReports = new ArrayList<Deposit>();
		boolean flag = false;
		Connection conn = getConnection();

		String query = ("SELECT deposit_id FROM deposits WHERE cust_id = " + cust_id);

		try {
			statement = conn.createStatement();
			resultSet = statement.executeQuery(query);

			while (resultSet.next()) {
				long deposit_id = resultSet.getLong("deposit_id");
				Deposit deposit = depositDBManager.getDepositById(deposit_id);
				listReports.add(deposit);

			}
			flag = true;
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		if (flag) {
			System.out.println("[ClientRepors] All deposit was added to report list");
		} else
			System.err.println("[ClientRepors] Deposit wasn't added to report list");

		return listReports;
	}

	// Get actions's List balance of customer by ID

	public List getListActionsByCust_id(long cust_id) throws DBManagerException {

		listReports = new ArrayList();
		boolean flag = false;
		Connection conn = getConnection();

		String query = ("SELECT balance_id FROM balance WHERE cust_id = " + cust_id);

		try {
			statement = conn.createStatement();
			resultSet = statement.executeQuery(query);

			while (resultSet.next()) {
				long balance_id = resultSet.getLong("balance_id");
				Balance balance = balanceDBManager.getBalanceById(balance_id);
				listReports.add(balance);

			}
			flag = true;
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		if (flag) {
			System.out.println("[ClientRepors] All Action's current Customer was added to report list ");
		} else
			System.err.println("[ClientRepors] Action's current Customer wasn't added to report list");

		return listReports;
	}

	// Get actions's List balance of customer by ID

	public Account getAccountByID(long account_id) throws DBManagerException {
		Account account = accountDBManager.getAccountById(account_id);
		return account;

	}

}
